<template>
    <div>
        <Position :navList="navList"/>
        <div class="detail">
            
            <div class="content">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="类型" prop="style">
                        <el-select v-model="ruleForm.style" placeholder="请选择广告类型">
                        <el-option label="图片" value="img"></el-option>
                        <el-option label="视频" value="video"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="标题" prop="name">
                        <el-input v-model="ruleForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="描述" prop="des">
                        <el-input v-model="ruleForm.des"></el-input>
                    </el-form-item>
                    <el-form-item label="上传" prop="file">
                        <el-upload
                        :limit="1"
                        class="upload"
                        drag
                        action=""
                        :http-request="ad_upload"
                        multiple>
                            <i class="el-icon-upload"></i>
                            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                        </el-upload>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script>
import Position from '../../components/position.vue'
export default {
    components:{
        Position
    },
    data(){
        return{
            navList:[{
                name:'广告管理',
                url:'/ad'
            },{
                name:'详情',
                url:''
            }],
            ruleForm: {
                name: '',//标题
                style:'',//类型
                des:'',//描述
                file:null,
            },
            rules: {
                name: [
                    { required: true, message: '请输入标题', trigger: 'blur' }
                ],
                des: [
                    { required: true, message: '请输入描述', trigger: 'blur' }
                ],
                style: [
                    { required: true, message: '请选择上传类型', trigger: 'change' }
                ]
            }
        }
    },
    mounted(){

    },
    methods:{
        //上传
        ad_upload(e){
            console.log(e)
        },
        //提交表单
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        //重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
}
</script>
<style lang="scss" scoped>
    .detail{
        padding: 5px;
        width: calc(100% - 10px);
        height: calc(100% - 10px);
        background-color: #fff;
        .content{
            width: 30%;
            margin-top: 40px;
            text-align: left;
        }
    }
</style>